package com.com.knowledgepaymentmanagementsystem.controller.marketing;

import com.com.knowledgepaymentmanagementsystem.pojo.marketing.Group;
import com.com.knowledgepaymentmanagementsystem.service.marketing.GroupService;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 冯炜轩
 * @Date 2025/9/23 15:10
 * @Version 1.0
 * @Description: 
 */

@Api(tags = "拼团管理")
@RestController
@CrossOrigin
@RequestMapping("/group")
public class GroupController {
    @Autowired
    private GroupService groupService;

    @ApiOperation(value = "查询拼团数据",httpMethod = "POST",notes = "查询拼团数据")
    @PostMapping("/find")
    public ResultUtil<List<Group>> getGroup(@RequestBody Group group){
        List<Group> groups = groupService.getGroup(group);
        try {
            return new  ResultUtil<>(200,"查询成功",groups);
        } catch (Exception e) {
            e.printStackTrace();
            return new  ResultUtil<>(200,"查询失败");

        }
    }

    @ApiOperation(value = "新增拼团数据",httpMethod = "POST",notes = "新增拼团数据")
    @PostMapping("insert")
    public ResultUtil insertGroup(@RequestBody Group group){
        try {
            return new ResultUtil<>(200,"新增成功",groupService.insertGroup(group));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"新增失败");
        }
    }

    @ApiOperation(value = "修改拼团数据",httpMethod = "PUT",notes = "修改拼团数据")
    @PutMapping("/update")
    public ResultUtil updateGroup(@RequestBody Group group){

        groupService.updateGroup(group);
        try {
            return new ResultUtil(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"修改失败");

        }
    }

    @ApiOperation(value = "删除拼团数据",httpMethod = "DELETE",notes = "删除拼团数据")
    @DeleteMapping("/delete")
    public ResultUtil deleteGroup(Integer id){
        groupService.deleteGroup(id);
        try {
            return new ResultUtil(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"删除失败");

        }
    }
}
